<?php

function post_email_by_sae($title, $body, $users) {

    if (defined('OPEN_EMAIL_SAE') && !OPEN_EMAIL_SAE) {
        log::w('Limit By Const OPEN_EMAIL_SAE,OPEN_EMAIL_SAE is false,Not Send Email');
        return false;
    }

    if (!is_array($users)) {
        $users = explode(',', $users);
    }

    $api = 'http://imail.sinaapp.com/sapi.php';
    $data = array(
        'title' => $title,
        'body' => $body,
        'to' => implode(',', $users)
    );

    $post_variables = $data;
    $content = http_build_query($post_variables);
    $content_length = strlen($content);
    $options = array(
        'http' => array(
            'method' => 'POST',
            'header' => "Content-type: application/x-www-form-urlencoded\r\n" .
            "Content-length: $content_length\r\n",
            'content' => $content,
            'timeout' => 60,
        )
    );
    $context = stream_context_create($options);

    return file_get_contents($api, false, $context);
}

?>